/* 
 * File:   math_macros.h
 * Author: gustavo
 *
 * Created on December 30, 2011, 2:41 AM
 */

#ifndef MATH_MACROS_H
#define	MATH_MACROS_H

#ifdef	__cplusplus
extern "C" {
#endif

#ifndef ABS
#define ABS(a)		( (a)< 0 ? -(a) : (a) )
#endif

#ifndef SIGN
#define SIGN(a)		( (a)< 0 ? -1 : 1 )
#endif

#ifndef CLAMP
#define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
#endif
	
#define __CEIL(a)	( (a)>0	? (long)(a)+1 : (long)(a) )
#define CEIL(a)		( ( ( (a)-(long)(a) ) != 0 )	?	__CEIL(a)	:	( (long)(a) ) )

#define __FLOOR(a)	( ( (a)<0 )	?	( (long)(a)-1 )	:	( (long)(a) ) )
#define FLOOR(a)	( ( ( (a)-(long)(a) ) != 0 )	?	__FLOOR(a)	:	( (long)(a) ) )

#define FIX(a)		((a)>0)		?	FLOOR(a)		:	CEIL(a)
#define ROUND(a)	((a)>=0)	?	(long)((a)+0.5)	: (long)((a)-0.5)

#ifndef M_PI
#define M_PI		3.14159265358979323846	/* pi */
#endif

#define rad2deg(r) (r)*180/M_PI
#define deg2rad(r) (r)*M_PI/180


#ifdef	__cplusplus
}
#endif

#endif	/* MATH_MACROS_H */

